package model;

import util.GameUtil;
import view.GameScreen;

public class Projectile extends Entity {	
	private GameScreen gameScreen;	
	private boolean used = false;
	
	public Projectile(GameScreen gameScreen, String sprite, int x, int y) {
		super(sprite,x,y);
		this.gameScreen = gameScreen;		
	}
	
	public void move(long delta) {		

		if ((dx < 0) && (x < 10)) {
			gameScreen.removeEntity(this);
		}
		
		if ((dy < 0) && (y < 10)) {
			gameScreen.removeEntity(this);
		}

		if ((dx > 0) && (x > GameUtil.GAME_SCREEN_WIDTH-this.sprite.getWidth())) {
			gameScreen.removeEntity(this);
		}	
		
		if ((dy > 0) && (y > GameUtil.GAME_SCREEN_HEIGHT-this.sprite.getHeight())) {
			gameScreen.removeEntity(this);
		}
		
		super.move(delta);
	}

	/**
	 * Notification that this shot has collided with another
	 * entity
	 * 
	 * @parma other The other entity with which we've collided
	 */
	public void collidedWith(Entity other) {
		// prevents double kills, if we've already hit something,

		// don't collide

		if (used) {
			return;
		}

		if (other instanceof Tank) {
			// remove the affected entities

			gameScreen.removeEntity(this);
			gameScreen.removeEntity(other);			
		}
	}	
}
